package com.xuecheng.media.controller;

import com.xuecheng.api.media.OperationMediaControllerApi;
import com.xuecheng.api.media.model.dto.MediaAuditDTO;
import com.xuecheng.api.media.model.dto.MediaDTO;
import com.xuecheng.api.media.model.qo.QueryMediaModel;
import com.xuecheng.api.media.model.vo.MediaAuditVo;
import com.xuecheng.common.domain.page.PageRequestParams;
import com.xuecheng.common.domain.page.PageVO;
import com.xuecheng.media.convert.OperationMediaConvert;
import com.xuecheng.media.service.OperationMediaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 黄子弟
 * @Date 2021/12/15
 */

@Slf4j
@RestController
public class OperationMediaController implements OperationMediaControllerApi {

    @Autowired
    private OperationMediaService operationMediaService;

    @Override
    @PostMapping("/m/media/list")
    public PageVO queryMediaList(PageRequestParams params, @RequestBody QueryMediaModel model) {
        PageVO<MediaDTO> pageVO = operationMediaService.queryMediaList(params, model);
        return pageVO;
    }

    @Override
    @PutMapping("/m/media/audit")
    public void modifyAuditStatus(@RequestBody MediaAuditVo vo) {
        MediaAuditDTO mediaAuditDTO = OperationMediaConvert.INSTANCE.vo2dto(vo);
        operationMediaService.modifyAuditStatus(mediaAuditDTO);
    }

    @Override
    @GetMapping("/m/media/preview/{mediaId}")
    public String previewMedia(@PathVariable Long mediaId) {
        String url = operationMediaService.previewMedia(mediaId);
        return url;
    }



}
